using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Publicuse.Entity;
using Publicuse.Util;

namespace Publicuse.Export
{
  /// <summary>
  /// 角色信息辅助类
  /// </summary>
  public class RoleExport
  {
    /// <summary>
    /// 角色导出数据设置
    /// </summary>
    /// <param name="fileName"></param>
    /// <param name="excelName"></param>
    /// <param name="list"></param>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static MemoryStream ExportData(
      string fileName,
      string excelName,
      List<Role> list,
      out string msg
    )
    {
      msg = string.Empty;
      MemoryStream ms = ExcelUtil.GetExcelUtil.InitExportData(
        fileName,
        excelName,
        list,
        (row, cell, sheet1, TextSytle, srow, hssfworkbook) =>
        {
          foreach (Role item in list)
          {
            srow++;
            row = sheet1.CreateRow(srow);

            //角色名称
            cell = row.CreateCell(0);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.rName);

            //角色编码
            cell = row.CreateCell(1);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.rCode);

            //状态
            cell = row.CreateCell(2);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.status == 1 ? "启用" : "停用");

            //所属上级
            cell = row.CreateCell(3);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.parentName);

            //创建时间
            cell = row.CreateCell(4);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.cTime.ToString("yyyy-MM-dd HH:mm:ss"));

            //更新时间
            cell = row.CreateCell(5);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.uTime?.ToString("yyyy-MM-dd HH:mm:ss"));

            //描述
            cell = row.CreateCell(6);
            cell.CellStyle = TextSytle;
            cell.SetCellValue(item.Remark);
          }
        },
        out msg,
        2
      );
      return ms;
    }
  }
}
